<template>
	<view>
		 <u-tabs :list="tabs" :is-scroll="false" v-model="current" @change="change"></u-tabs>
		 <u-cell-item v-for="(item, index) in list" :key="index" :arrow="false" :title="item.content" :value="item.status_str" title-width="600"></u-cell-item>
		<view v-if="list.length==0" class="u-m-t-50">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
		<view v-if="list.length>0">
			<u-loadmore :status="loadStatus" margin-top="50"></u-loadmore>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	var vk = uni.vk;
	export default {
		data() {
			// 页面数据变量
			return {
				tabs: [{
					name: '邮箱'
				}, {
					name: '课程'
				}, {
					name: '服务器'
				},{
					name: '新闻'
				}, {
					name: '一卡通'
				}, {
					name: '校园网'
				}],
				current: 0,
				loadStatus: 'loadmore',
				list: [],
				postData: {
					"pageIndex": 1,
					"pageSize": 50,
					"formData": {
						"user_id": ""
					},
					"columns": [{
						key: "user_id",
						title: "用户编号",
						type: "text",
						mode: "="
					}]
				},
				scrollTop: 0
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			vk = uni.vk;
			this.options = options;
			this.init(options);
		},
		onReachBottom() {
			if(this.loadStatus == 'nomore'){
				return
			}
			this.postData.pageIndex+=1
			this.getList();
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行（如：前进和返回）（页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面）
		onShow() {

		},
		// 监听 - 页面每次【隐藏时】执行（如：返回）
		onHide() {},
		// 监听 - 页面每次【卸载时】（一般用于取消页面上的监听器）
		onUnload() {},
		// 监听 - 页面下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.list = []
				this.postData.pageIndex=1
				this.getList(0)
				uni.stopPullDownRefresh();
			}, 1000);
		},
		/**
		 * 监听 - 点击右上角转发时 文档 https://uniapp.dcloud.io/api/plugins/share?id=onshareappmessage
		 * 如果删除onShareAppMessage函数，则微信小程序右上角转发按钮会自动变灰
		 */
		onShareAppMessage(options) {

		},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options = {}) {
				console.log("init: ", options);
				this.postData.formData.user_id = vk.getVuex('$user.userInfo')._id
				this.getList(0)			
			},
			async getList(cur){
				let that = this
				that.list = []
				let postData = that.postData
				switch (cur){
					case 0:
						var res = await vk.callFunction({
							url: 'client/email/pub/getList',
							title: '请求中...',
							data: postData,
						})
						if (res.code == 0) {
							for (let i = 0; i < res.rows.length; i++) {
								let item = res.rows[i]
								item.content = item.email
								if(item.status==0){
									item.status_str = '审核中'
								}else if (item.status==1) {
									item.status_str = '已通过'
								} else{
									item.status_str = '申请失败'
								}
								
								that.list.push(item);
							}
							if(res.hasMore == true){
								that.loadStatus = 'loadmore';
							}else{
								that.loadStatus = 'nomore';
							}					
						} else {
							that.loadStatus = 'nomore';
						} 
						break;
					case 1:
						var res = await vk.callFunction({
							url: 'client/curriculum/pub/getList',
							title: '请求中...',
							data: postData,
						})
						if (res.code == 0) {
							for (let i = 0; i < res.rows.length; i++) {
								let item = res.rows[i]
								item.content = item.title
								if(item.status==0){
									item.status_str = '审核中'
								}else if (item.status==1) {
									item.status_str = '已通过'
								} else{
									item.status_str = '申请失败'
								}
								
								that.list.push(item);
							}
							if(res.hasMore == true){
								that.loadStatus = 'loadmore';
							}else{
								that.loadStatus = 'nomore';
							}					
						} else {
							that.loadStatus = 'nomore';
						} 
						break;
					case 2:
						var res = await vk.callFunction({
							url: 'client/server/pub/getList',
							title: '请求中...',
							data: postData,
						})
						if (res.code == 0) {
							for (let i = 0; i < res.rows.length; i++) {
								let item = res.rows[i]
								item.content = item.server
								if(item.status==0){
									item.status_str = '审核中'
								}else if (item.status==1) {
									item.status_str = '已通过'
								} else{
									item.status_str = '申请失败'
								}
								
								that.list.push(item);
							}
							if(res.hasMore == true){
								that.loadStatus = 'loadmore';
							}else{
								that.loadStatus = 'nomore';
							}					
						} else {
							that.loadStatus = 'nomore';
						} 
						break;
					case 3:
						var res = await vk.callFunction({
							url: 'client/schoolNews/pub/getList',
							title: '请求中...',
							data: postData,
						})
						if (res.code == 0) {
							for (let i = 0; i < res.rows.length; i++) {
								let item = res.rows[i]
								item.content = item.content
								if(item.status==0){
									item.status_str = '审核中'
								}else if (item.status==1) {
									item.status_str = '已通过'
								} else{
									item.status_str = '申请失败'
								}
								
								that.list.push(item);
							}
							if(res.hasMore == true){
								that.loadStatus = 'loadmore';
							}else{
								that.loadStatus = 'nomore';
							}					
						} else {
							that.loadStatus = 'nomore';
						} 
						break;
					case 4:
						var res = await vk.callFunction({
							url: 'client/onecard/pub/getList',
							title: '请求中...',
							data: postData,
						})
						if (res.code == 0) {
							for (let i = 0; i < res.rows.length; i++) {
								let item = res.rows[i]
								item.content = "卡号: "+item.cardNo
								if(item.status==0){
									item.status_str = '审核中'
								}else if (item.status==1) {
									item.status_str = '已通过'
								} else{
									item.status_str = '申请失败'
								}
								
								that.list.push(item);
							}
							if(res.hasMore == true){
								that.loadStatus = 'loadmore';
							}else{
								that.loadStatus = 'nomore';
							}					
						} else {
							that.loadStatus = 'nomore';
						} 
						break;
					case 5:
						var res = await vk.callFunction({
							url: 'client/campus/pub/getList',
							title: '请求中...',
							data: postData,
						})
						if (res.code == 0) {
							for (let i = 0; i < res.rows.length; i++) {
								let item = res.rows[i]
								item.content = "学号: "+item.sid
								if(item.status==0){
									item.status_str = '审核中'
								}else if (item.status==1) {
									item.status_str = '已通过'
								} else{
									item.status_str = '申请失败'
								}
								
								that.list.push(item);
							}
							if(res.hasMore == true){
								that.loadStatus = 'loadmore';
							}else{
								that.loadStatus = 'nomore';
							}					
						} else {
							that.loadStatus = 'nomore';
						} 
						break;
					default:
						break;
				}							
			},
			change(index) {
				console.log("index", index);
				this.getList(index)
			},
			pageTo(path) {
				vk.navigateTo(path);
			},
		},
		// 监听器
		watch: {

		},
		// 计算属性
		computed: {

		}
	}
</script>
<style lang="scss" scoped>
.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #d0d0d0;
	}
	
	.u-order-title {
		color: #333333;
		font-weight: bold;
		font-size: 32rpx;
	}
	
	.u-order-desc {
		color: rgb(150, 150, 150);
		font-size: 28rpx;
		margin-bottom: 6rpx;
	}
	
	.u-order-time {
		color: rgb(200, 200, 200);
		font-size: 26rpx;
	}
</style>